using SqlSugar;
using IM.Easy.Core.Audit;

namespace IM.Easy.Entity.Msg
{
    /// <summary>
    /// 邮件表
    /// </summary>
    [SugarTable("Emails")]
    public class Emails : AuditableEntity
    {
        /// <summary>
        /// 发件人用户ID
        /// </summary>
        [SugarColumn(ColumnName = "SenderId")]
        public long SenderId { get; set; }

        /// <summary>
        /// 收件方
        /// </summary>
        [SugarColumn(IsJson = true, ColumnName = "AudienceId", ColumnDataType = "text")]
        public List<long>? AudienceId { get; set; } = [];

        /// <summary>
        /// 邮件主题
        /// </summary>
        [SugarColumn(ColumnName = "Subject")]
        public string? Subject { get; set; }

        /// <summary>
        /// 邮件正文
        /// </summary>
        [SugarColumn(ColumnName = "Body")]
        public string? Body { get; set; }

        /// <summary>
        /// 邮件正文摘要
        /// </summary>
        public string? Abstract { get; set; }

        /// <summary>
        /// 发送时间
        /// </summary>
        [SugarColumn(ColumnName = "SentTime")]
        public DateTime? SentTime { get; set; }

        /// <summary>
        /// 邮件状态 (0: 草稿, 1: 已发送, 2: 已撤回，-1：已删除)
        /// </summary>
        [SugarColumn(ColumnName = "Status")]
        public EmailStatus Status { get; set; }

        /// <summary>
        /// 收件箱
        /// </summary>
        [Navigate(NavigateType.OneToMany, nameof(EmailRecives.EmailId))]
        public List<EmailRecives> Recives { get; set; }

        /// <summary>
        /// 发送方
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(SenderId))]
        public EmailAccount Sender { get; set; }

    }

    public enum EmailStatus
    {
        /// <summary>
        /// 草稿
        /// </summary>
        Draft = 0,

        /// <summary>
        /// 已发送
        /// </summary>
        Sent = 1,

        /// <summary>
        /// 已撤回
        /// </summary>
        Withdrawn = 2,

        /// <summary>
        /// 已删除
        /// </summary>
        Deleted = -1
    }
}
